package guo.Interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Component
public class MvcInterceptorOne implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String auth = request.getHeader("auth");
        request.getSession().setAttribute("auth","valueeee");
//        Object auth = request.getSession().getAttribute("auth");
        if (auth == null){
            System.out.println("错误了，未登录");;
            return false;
        }else {
            System.out.println("正确的。已经登陆的");
            return true;
        }
    }
}
